
#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;

using Xeno_Race.Graphics;
#endregion

namespace Xeno_Race.GameScreens
{
	/// <summary>
	/// Multiplayer Ingame Screen (HUD and 3D)
	/// </summary>
	class MultiGame : IGameScreen
	{
		#region Properties
		/// <summary>
		/// Name of this game screen
		/// </summary>
		/// <returns>String</returns>
		public string Name
		{
			get
			{
				return "MultiGame";
			} // get
		} // Name

		private bool quit = false;
		/// <summary>
		/// Returns true if we want to quit this screen and return to the
		/// previous screen. If no more screens are left the game is exited.
		/// </summary>
		/// <returns>Bool</returns>
		public bool Quit
		{
			get
			{
				return quit;
			} // get
		} // Quit

		/// <summary>
		/// Reset camera when starting.
		/// </summary>
		public bool resetCamera = true;
		#endregion

        #region speed vars
        private float speedQuotientFloat;
        private int speedQuotient = 0;
        private int[] value = new int[3];
        private SpriteHelper[] speedSpriteHelper = new SpriteHelper[3];
        private SpriteHelper redPlane;
        #endregion

		#region Constructor
		/// <summary>
        /// Create ingame Screen for MultiGame
		/// </summary>
        public MultiGame()
		{
		}
		#endregion

		#region Run
		/// <summary>
		/// Run game screen. Called each frame.
		/// </summary>
		/// <param name="game">Form for access to other stuff</param>
		public void Run(XenoGame game)
		{
            TextureFont.WriteText(1024 / 2 - 500, 2, game.Player.Name);
            TextureFont.WriteText(1024 / 2 + 12, 2, game.Player2.Name);
            TextureFont.WriteText(1024 / 2 - 84, 64, game.Player.getCurrentTime());

            renderSpeedo(game, 1024/2, game.ships[game.Player.ShipSelection].getSpeed());

            renderSpeedo(game, 1024, game.ships[game.Player2.ShipSelection].getSpeed());

            if ((game.currentInputState.ExitButton && !game.previousInputState.ExitButton) ||
                (game.currentInputState.XButton && !game.previousInputState.XButton))
            {
                game.Sounds.play(SoundManager.Sound.Sounds.Click);
                quit = true;
            }

		} // Run(game)
		#endregion

        private void renderSpeedo(XenoGame game, int x, int speed)
        {
            speedQuotientFloat = speed;
            speedQuotient = (int)((speedQuotientFloat / 132) * 263);

            redPlane = new SpriteHelper(game.hudTexture, new Rectangle(0, 209, speedQuotient, 100));
            
            game.whiteFrame.Render(x - 270, 768 - 112);
            redPlane.Render(x - 270, 768 - 111);
            game.greyPlane.Render(x - 270, 768 - 110);
            
            value[0] = speed % 10;
            speed /= 10;
            value[1] = speed % 10;
            speed /= 10;
            value[2] = speed % 10;

            for (int i = 0; i < 3; i++)
            {
                switch (value[i])
                {
                    case 0: speedSpriteHelper[i] = game.hud0;
                        break;
                    case 1: speedSpriteHelper[i] = game.hud1;
                        break;
                    case 2: speedSpriteHelper[i] = game.hud2;
                        break;
                    case 3: speedSpriteHelper[i] = game.hud3;
                        break;
                    case 4: speedSpriteHelper[i] = game.hud4;
                        break;
                    case 5: speedSpriteHelper[i] = game.hud5;
                        break;
                    case 6: speedSpriteHelper[i] = game.hud6;
                        break;
                    case 7: speedSpriteHelper[i] = game.hud7;
                        break;
                    case 8: speedSpriteHelper[i] = game.hud8;
                        break;
                    case 9: speedSpriteHelper[i] = game.hud9;
                        break;

                }
            }
            speedSpriteHelper[2].Render(x - 252, 768 - 100);
            speedSpriteHelper[1].Render(x - 216, 768 - 100);
            speedSpriteHelper[0].Render(x - 180, 768 - 100);
        }
	} // class MainMenu
}